package cn.wang.heng.make;
import java.util.ArrayList;
import cn.wang.heng.text.*;
public class shopCar {
	private ArrayList buylist=new ArrayList();
	public void setBuylist(ArrayList buylist){
		this.buylist=buylist;
	}
	
	public void addgood(ShangPin goods){
		if(goods!=null){
			if(buylist.size()==0 || buylist==null){
				int aa=1;
				ShangPin goodlist =new ShangPin();
				goodlist.setGoodname(goods.getGoodname());
				goodlist.setGoodaccount(goods.getGoodaccount());
				goodlist.setGoodid(goods.getGoodid());
				goodlist.setGoodprice(goods.getGoodprice());
				goodlist.setNum(aa);
				buylist.add(goodlist);
			}
			else{
				int i=0;
				for(;i<buylist.size();i++){
					ShangPin goodlist =(ShangPin)buylist.get(i);
					if(goodlist.getGoodname().equals(goods.getGoodname())){
						goodlist.setNum(goodlist.getNum()+1);
						break;
					}
				}
				if(i>=buylist.size()){
					ShangPin goodlist =new ShangPin();
					goodlist.setGoodname(goods.getGoodname());
					goodlist.setGoodaccount(goods.getGoodaccount());
					goodlist.setGoodid(goods.getGoodid());
					goodlist.setGoodprice(goods.getGoodprice());
					goodlist.setNum(goods.getNum());
					buylist.add(goodlist);
				}
			}
		}
	}
	public void removegood(String name){
		for(int i=0;i<buylist.size();i++){
			ShangPin goodlist=(ShangPin)buylist.get(i);
			if(goodlist.getGoodname().equals(name)){
				if(goodlist.getNum()>1){
					goodlist.setNum(goodlist.getNum()-1);
					break;
				}
				else if(goodlist.getNum()==1){
					buylist.remove(i);
				}
			}
		}
	}
}
